package dst.ass1.jpa.model.impl;

import java.util.Date;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;

import dst.ass1.jpa.model.IMembership;
import dst.ass1.jpa.model.IMembershipKey;
import dst.ass1.jpa.model.IUser;
import dst.ass1.jpa.model.IWorkPlatform;

@Entity
public class Membership implements IMembership{

	@EmbeddedId   //is an EmbeddedId (Class)
	private MembershipKey id;
	
	private Date registration;
	
	private Double discount;
	
	@MapsId("workPlatform")
	@ManyToOne(targetEntity=WorkPlatform.class, fetch=FetchType.EAGER)  //to-one properties are loaded eagerly (as loading them is cheap))
	private IWorkPlatform workPlatform;

	@MapsId("user")
	@ManyToOne(targetEntity=User.class, fetch=FetchType.EAGER)  //to-one properties are loaded eagerly (as loading them is cheap))
	private IUser user;
	
	public Membership() {
	}

	@Override
	public IMembershipKey getId() {
		return id;
	}

	@Override
	public void setId(IMembershipKey id) {
		this.id = (MembershipKey) id;
	}

	@Override
	public Date getRegistration() {
		return registration;
	}

	@Override
	public void setRegistration(Date registration) {
		this.registration=registration;
	}

	@Override
	public Double getDiscount() {
		return discount;
	}

	@Override
	public void setDiscount(Double discount) {
		this.discount=discount;
	}

}
